package com.solidumgame.locroninja.juego
{
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.geom.Vector3D;
	import flash.text.TextField;
	import flash.ui.Keyboard;
	
	import libs.away3d.cameras.HoverCamera3D;
	import libs.away3d.containers.ObjectContainer3D;
	import libs.away3d.containers.View3D;
	import libs.away3d.core.base.Mesh;
	import libs.away3d.core.utils.Cast;
	import libs.away3d.core.utils.HitManager;
	import libs.away3d.events.MouseEvent3D;
	import libs.away3d.lights.DirectionalLight3D;
	import libs.away3d.loaders.Collada;
	import libs.away3d.materials.ColorMaterial;
	import libs.away3d.primitives.Cube;
	import libs.away3d.primitives.Plane;
	import libs.jiglib.physics.RigidBody;


	
	
	public class Escenario extends View3D
	{
		[Embed(source="./assets/texturas/escena/Muebles.jpg")] // MIME-type important!
		private static var ArmariosTextura : Class;
		
		[Embed(source="./assets/texturas/escena/Armarios.dae",mimeType="application/octet-stream")] // MIME-type important!
		private static var ArmariosDAE : Class;
		
		[Embed(source="./assets/texturas/escena/Pared.jpg")] // MIME-type important!
		private static var ParedTextura : Class;
		
		[Embed(source="./assets/texturas/escena/Pared.dae",mimeType="application/octet-stream")] // MIME-type important!
		private static var ParedDAE : Class;
		
		
		public  var limiteHorizontalInferior:int;
		public  var limiteHorizontalSuperior:int;
		public  var limiteVerticalIzquierdo:int;
		public  var limiteVerticalDerecho:int;
		
		private var cam:HoverCamera3D;
		private var lastKey:uint;
		private var keyIsDown:Boolean = false;
		
		public function Escenario(posX:Number, posY:Number)
		{
			//Inicializamos Vista, Escena y Camara en posicion especificada
			super({x:posX,y:posY });
			
			limiteHorizontalInferior = -Partida.stage.stageHeight/2;
			limiteHorizontalSuperior = Partida.stage.stageHeight/2;
			limiteVerticalIzquierdo = -Partida.stage.stageWidth/2;
			limiteVerticalDerecho = Partida.stage.stageWidth/2;
			
			this.mouseZeroMove = true;
			
			
			var light:DirectionalLight3D = new DirectionalLight3D();
			this.scene.addLight(light);
			light.direction = new Vector3D(200,-300,400);
			light.specular = 0;
			light.diffuse = 0.7;
			light.ambient = 0.5;
			
			/*
			var armarios:ObjectContainer3D = Collada.parse(ArmariosDAE,{z:400,autoLoadTextures:false}); 
			
			(armarios.children[0] as Mesh).material = Cast.material(ArmariosTextura);
			
			
			this.scene.addChild(armarios);
			
			
			
			var pared:ObjectContainer3D = Collada.parse(ParedDAE,{z:400,autoLoadTextures:false}); 
			
			(pared.children[0] as Mesh).material = Cast.material(ParedTextura);
			
			
			this.scene.addChild(pared);
			
			*/
			/*
			var pared:Plane = new Plane({width:2000,height:2000,rotationX:90,z:500});
		
			pared.mouseEnabled = false;
			pared.pushback = true;
			this.scene.addChild(pared);
			*/
			/*cam = new HoverCamera3D();
			cam.z = -1000; // make sure it's positioned away from the default 0,0,0 coordinate
			cam.panAngle = 0;
			cam.tiltAngle = 0;
			cam.minTiltAngle = -90;
			cam.hover(true);
			cam.distance = 800;
			*/
			
			
			/*Partida.stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
			Partida.stage.addEventListener(KeyboardEvent.KEY_UP,keyUp);
			Partida.stage.addEventListener(Event.ENTER_FRAME,update);*/
		}
		
		/*

		
		private function keyDown(e:KeyboardEvent):void
		{
			
			lastKey = e.keyCode;
			keyIsDown = true;
		}
		private function keyUp(e:KeyboardEvent):void
		{
			keyIsDown = false;
		}
	
		
		public function update(e:Event):void
		{
			
			var event:MouseEvent3D = this.hitManager.getMouseEvent(MouseEvent3D.MOUSE_MOVE);
			Partida.cuchillo.cuchilloFisica.moveTo(new Vector3D(event.sceneX,event.sceneY,0));
			
			if(keyIsDown){
				// if the key is still pressed, just keep on moving
				switch(lastKey){
					case 87				: cam.tiltAngle -= 10; break;
					case 83				: cam.tiltAngle += 10; break;
					case 65				: cam.panAngle -= 10; break;
					case 68				: cam.panAngle += 10; break;
					case Keyboard.UP	: cam.distance -= 10; break;
					case Keyboard.DOWN	: cam.distance += 10; break;
				}
				
			}
			cam.hover();
		}
		*/
	}
}